package com.newture.lxz.controller;

import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;

public class Ele {
    public int year;
    public int month;
    public int day;
    public double rate;
    public Ele(int year,int month,int day,double rate){
        this.year=year;
        this.month=month;
        this.day=day;
        this.rate=rate;
    }
    public static int getDaysOfaMonth(int mon){
        int d=0;
        switch(mon){
            case 1:d=31;break;
            case 2:d=29;break;
            case 3:d=31;break;
            case 4:d=30;break;
            case 5:d=31;break;
            case 6:d=30;break;
            case 7:d=31;break;
            case 8:d=31;break;
            case 9:d=30;break;
            case 10:d=31;break;
            case 11:d=30;break;
            case 12:d=31;break;
        }
        return d;
    }
    public static int getMonthDifference(Ele e1,Ele e2){
        int num=0;
        if(e1.getYear()<e2.getYear()) {
            num += 12-e1.getMonth()+e2.getMonth();
            num+=(Math.abs(e1.getYear() - e2.getYear())-1) * 12;
        }else if(e1.getYear()>e2.getYear()){
            num+=12-e2.getMonth()+e1.getMonth();
            num+=(Math.abs(e1.getYear() - e2.getYear())-1) * 12;
        }else{
            num+=Math.abs(e1.getMonth()-e2.getMonth());
        }
        return num;
    }
    public static int getDaysDifference(Ele e1,Ele e2){
        LocalDate ld1=LocalDate.of(e1.getYear(),e1.getMonth(),e1.getDay());
        LocalDate ld2=LocalDate.of(e2.getYear(),e2.getMonth(),e2.getDay());
        int daysDiff = (int)ChronoUnit.DAYS.between(ld1, ld2);
        return daysDiff;
    }
    public static Ele addOneMonth(Ele e){
        int y=e.getYear();
        int mon=e.getMonth();
        int d=e.getDay();
        double r=e.getRate();
        if(mon>=12){
            y+=1;
            mon=1;
        }else{
            mon++;
        }
        Ele newE=new Ele(y,mon,d,r);
        return newE;
    }
    public int getDaysofThisMonth(){
        return 1;
    }

    public int getYear(){
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    public static void main(String[] args) {
        LocalDate ld1=LocalDate.of(2019,12,21);
        LocalDate ld2=LocalDate.of(2020,1,14);
        int daysDiff = (int)ChronoUnit.DAYS.between(ld1, ld2);
        System.out.println(daysDiff);
    }
}
